import { defineStore } from "pinia";
import type { routerList } from '../type/user'

const userStore = defineStore('user',{
  state:()=>{
    return {
      userId: sessionStorage.getItem('userId') || '',
      nickName: sessionStorage.getItem('nickName') || '',
      avator: sessionStorage.getItem('avator') || '',
      routerList: JSON.parse(sessionStorage.getItem('routerList')),
      menuList: JSON.parse(sessionStorage.getItem('menuList')),
      token: sessionStorage.getItem('token') || '',
    }
  },
  getters:{
    routes:(state)=> state.routerList,
    tokenGet:(state)=>state.token,
    menuListGet:(state)=>state.menuList,
  },
  actions:{
    setRouterList (payload: routerList){
      this.routerList = payload
    }, 
    setMenuList(payload: routerList) {
      this.menuList = payload
    },
    setToken(payload: string){
      this.token = payload
    }

  }
})

export default userStore